package com.tensquare.qa.dao;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.tensquare.qa.pojo.Problem;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 数据访问接口
 * @author Administrator
 *
 */
public interface ProblemDao extends JpaRepository<Problem,String>,JpaSpecificationExecutor<Problem>{

    // nativeQuery属性：表示使用SQL语句
    @Query(value = "select * from tb_problem", nativeQuery = true)
    public List<Problem> find();
     // * 最新回答

    /**
     * Pageable: 传递了Pageable参数之后，就会进行分页查询
     */
    @Query(value = "SELECT * FROM tb_pl,tb_problem WHERE problemid=id AND labelid=? ORDER BY createtime DESC", nativeQuery = true) // nativeQuery表示使用SQL语句
    public Page<Problem> newList(String labelid, Pageable pageable);

    /**
     * 热门回答
     */
    @Query(value = "SELECT * FROM tb_pl,tb_problem WHERE problemid=id AND labelid=? ORDER BY reply DESC", nativeQuery = true)
    public Page<Problem> hotList(String labelid, Pageable pageable);

    /**
     * 等待回答
     */
    @Query(value = "SELECT * FROM tb_pl,tb_problem WHERE problemid=id AND labelid=? AND reply=0 ORDER BY createtime DESC", nativeQuery = true)
    public Page<Problem> waitList(String labelid, Pageable pageable);
}
